# -*- coding: utf-8 -*-
# @File    : get_comp_info.py
# @Date    : 2021-11-26
# @Author  : Richard

import os
import time
import configparser


class GetCompName(object):
    """
    根据IP地址获取单位名称
    """
    def __init__(self, file):
        self.file = file

    def get_comp(self, ip):
        try:
            cf = configparser.ConfigParser()
            cf.read(self.file, encoding="gbk")
            comp_name = cf.get("comp", ip)
            if comp_name:
                return comp_name
            else:
                print("没有这个单位，IP-->:{0}".format(ip))
        except Exception as Err:
            print("获取单位名称发生错误:{0}".format(Err))
